<template>
    <noticeDetail ref="noticeDetail" />
    <noticePersonal ref="noticePersonal" />

    <div class="container">
        <div class="notice_li flex" v-for="item in list">
            <!-- <div class="imgBox">
                <img src="../../assets/l3.png" alt="">
            </div> -->
            <div class="notice_box">
                <p class="title">{{ item.title }}</p>
                <p class="intro">
                    <el-text line-clamp="2">{{ item.summary }}</el-text>
                </p>
                <div class="notice_bottom flex">
                    <div class="flex" style="flex: 1;">
                        <p class="pTime">{{ item.createdAt }}</p>
                        <p class="personnel"><el-text line-clamp="1">接收人员：信息技术中心、电教中心、行政效能中心 </el-text>
                        </p>
                    </div>
                    <div class="btn_box flex">
                        <p @click="lookOver(item)">查看详情</p>
                        <p @click="editApp(item)">编辑</p>
                        <p @click="deleteApp(item.id)">删除</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="page_box">
            <el-config-provider :locale="locale">
                <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                    layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                    @current-change="changeCurrentPage">
                </el-pagination>
            </el-config-provider>
        </div>
    </div>
</template>

<script>
import noticeDetail from "@/components/noticeCopy/noticeDetail.vue";
import bottomView from "@/components/bottom.vue";
import noticePersonal from "@/components/noticeCopy/noticePersonal.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture } from "@element-plus/icons-vue";
import { mapActions } from 'vuex';

export default {
    name: "BaseTeacherList",

    data() {
        return {
            type: 0,
            title: "",
            page: 1,
            pageSize: 5,
            total: 0,
            limit: 5,
            list: [],
            flagId: '',
            form: {
                title: "",
            },
            selectData: {},
            mobileNumber: '',
        };
    },
    components: {
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, noticeDetail,
        bottomView, noticePersonal,
    },
    watch: {
    },
    setup() {
        return {
            locale: zhCn,
        }
    },
    mounted() {
        this.getNoticeList();
    },
    watch: {
        $route() {
            this.getNoticeList();
        },
    },
    methods: {
        ...mapActions(['uploadAdd']),
        searchEnter: function (e) {
            console.log(e);
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getNoticeList();
            }
        },
        editApp(obj) {
            this.$router.push({ path: '/noticeCopyIndexView/noticeCopyEditPublishView', query: { id: obj.id } })
        },
        lookOver(obj) {
            const touterData = {
                label: "通知详情",
                id: 1000,
                levelName: "通知详情",
                icon: "noticeIcon1.png",
                path: "/noticeCopyIndexView/NoticeCopyDetial",
                code: 1000,
                level: 2,
                parentId: 188,
                children: []
            }
            this.uploadAdd(touterData)
            this.$router.push({ path: '/noticeCopyIndexView/NoticeCopyDetial', query: { id: obj.id } })

            // this.$refs.noticeDetail.title = "查看详情";
            // this.$refs.noticeDetail.dialogFormVisible = true;
            // this.$refs.noticeDetail.queryNotice(obj.id)
            // this.$refs.noticeDetail.readhandle(obj.id)
            // this.$refs.noticeDetail.readList(obj.id)
        },
        deleteApp(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/messages/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getNoticeList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                })
                .catch(() => { });
        },
        onSubmit() {
            this.getNoticeList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getNoticeList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getNoticeList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getNoticeList() {
            httpService(
                "/javaApi/messages/list/" + this.page + "/" + this.pageSize,
                {
                    title: this.form.title,
                    type: 0,
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
        lookTeacher(data) {
            console.log(this.$refs.noticePersonal);
            this.$refs.noticePersonal.title = "接收人员";
            this.$refs.noticePersonal.dialogFormVisible = true;
            this.$refs.noticePersonal.queryId = data.id;
            this.$refs.noticePersonal.getListmy()
            this.$refs.noticePersonal.lookTeacher(data.id)
        },
    },
};
</script>

<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.container {
    margin-top: 20px;
    width: 100%;
}

.notice_li {
    /* width: calc(100% - 40px); */
    background-color: #fff;
    padding: 15px 20px 15px 10px;
    margin-bottom: 15px;
}

.notice_li .imgBox {
    min-width: 200px;
}

.notice_box {
    flex: 1;
    margin-left: 15px
}

.title {
    color: #000;
    font-size: 16px;
}

.intro {
    color: #666666;
    font-size: 12px;
    margin: 15px 0 20px;
    line-height: 24px;
}

.notice_bottom {
    color: #999;
    font-size: 12px;
    line-height: 12px;
    justify-content: space-between;
}

.pTime {
    margin-right: 50px;
}

.personnel {
    flex: 1;
    /* margin-top: 3px; */
}

.personnel .el-text {
    color: #999;
    font-size: 12px !important;
    line-height: 12px;
    margin-top: 1px;
}

.btn_box {
    margin-left: 50px;
}

.btn_box p {
    margin-left: 15px;
    cursor: pointer;
}

.page_box {
    background-color: #fff;
    padding: 15px 20px 15px 10px;
}
</style>